import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:sptapp/moudle/message.dart';
import 'package:sptapp/page/monitor/monitor_list.dart';
import '../../config/const.dart';

class MonitorPage extends StatefulWidget {
  const MonitorPage({super.key});

  @override
  State<MonitorPage> createState() => _MonitorPageState();
}

class _MonitorPageState extends State<MonitorPage> with SingleTickerProviderStateMixin{

  late TabController _tabController;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(length: 4, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: defaultBgColor,
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 30.w),
        child: Column(
          children: [
            SizedBox(height: ScreenUtil().statusBarHeight + 20.w,),
            Container(
              alignment: Alignment.centerLeft,
              child: TabBar(
                controller: _tabController,
                isScrollable: true,
                dividerHeight: 0,
                indicatorWeight: 2.w,
                labelPadding: EdgeInsets.only(right: 60.w),
                indicatorSize: TabBarIndicatorSize.label,
                padding: EdgeInsets.zero,
                tabAlignment: TabAlignment.start,
                indicator: BoxDecoration(
                    borderRadius: BorderRadius.circular(2),
                    color: themeColor
                ),
                indicatorPadding: EdgeInsets.only(left: 15.w, right: 15.w,top: 38,bottom: 7),
                labelStyle: TextStyle(
                    color: themeColor,
                    fontSize: 32.sp,
                    fontWeight: FontWeight.w600
                ),
                unselectedLabelStyle: TextStyle(
                    color: fontColor,
                    fontSize: 32.sp,
                    fontWeight: FontWeight.w600
                ),
                tabs: [
                  Tab(text: monitor_page_tab_all.tr,),
                  Tab(text: monitor_page_tab_online.tr,),
                  Tab(text: monitor_page_tab_offline.tr,),
                  Tab(text: monitor_page_tab_unbind.tr,),
                ],
              ),
            ),
            Expanded(
                child: Container(
                  margin: EdgeInsets.only(top: 15.w),
                  child: TabBarView(
                    controller: _tabController,
                    children: _buildTabViews(),
                  ),
                )
            )
          ],
        ),
      ),
    );
  }

  List<Widget> _buildTabViews(){
    List<Widget> arr = [];
    for(int i = 0; i < 4; i++){
      arr.add(MonitorListPage(status: i == 0? '': i == 1? '1': i == 2? '0': '2',));
    }
    return arr;
  }
}
